package Lee_code;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @author blh
 * @date 2024年07月02日 19:05
 */
public class Lee_209_72 {
    public int minSubArrayLen(int target, int[] nums) {
        int len = nums.length;
        int minLen = 99999999;
        int slow = 0;
        int fast = 0;
        int sum = nums[0];

        while (fast < len) {
            if (sum < target) {
                fast++;
                if (fast < len) {
                    sum += nums[len];
                }
            }
            if (sum >= target) {
                minLen = Math.min(minLen, fast - len + 1);
                sum = sum - nums[slow];
                slow++;
            }
        }
        return minLen == 99999999 ? 0 : minLen;
    }
}
